public class Bot extends Player {
	int id;
	String imie;
	String[][] karty = new String[2][5];
	int argumenty[] = new int[5];
	int wymiana;
	int masz;
	int str[] = new int[9];
	int ty[] = new int[4];
	int str0[] = new int[5];
	int str1[] = new int[5];
	int str2[] = new int[5];
	int str3[] = new int[5];
	int str4[] = new int[5];
	int str5[] = new int[5];
	int str6[] = new int[5];
	int str7[] = new int[5];
	int str8[] = new int[5];

	Bot(String imie) {
		this.imie = imie;
	}

	void losowanie_kart() {
		for (int i = 0; i < 5; i++) {
			String wylosowana_karta[][] = new String[2][1];
			wylosowana_karta = Talia.karty();
			karty[0][i] = wylosowana_karta[0][0];
			karty[1][i] = wylosowana_karta[1][0];
		}
	}

	void uzupelnieni_argumentow() {
		argumenty = Player.uzupelnianie_argumentow(karty, argumenty);
	}

	void ulozenie_kart() {
		karty = Talia.ulozenie(karty, argumenty);
		argumenty = Player.uzupelnianie_argumentow(karty, argumenty);
	}

	void wypis() {
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 5; j++) {
				System.out.print(karty[i][j] + "\t");
			}
			System.out.println("");
		}
		/*
		 * for (int i = 0; i < 5; i++) { System.out.print(argumenty[i] + "\t");
		 * } System.out.println();
		 */
	}

	// strategia
	void poker() {
		int pozycja = 0;
		int ilosc_kart = 0;
		kolor();
		if (str[3] == 0) {
			strit();
			if (str[4] == 0)
				ilosc_kart = 0;
			if (str[4] == 1) {
				for (int i = 0; i < 5; i++)
					str0[i] = str4[i];
				ilosc_kart = 1;
			}
			if (str[4] == 2) {
				for (int i = 0; i < 5; i++)
					str0[i] = str4[i];
				ilosc_kart = 2;
			}
			if (str[4] != 0 && str[4] != 1 && str[4] != 2)
				ilosc_kart = 10;
		}
		if (str[3] == 1) {
			strit();
			if (str[4] == 0) {
				for (int i = 0; i < 5; i++)
					str0[i] = str3[i];
			}
			if (str[4] == 1) {
				boolean k = false;
				for (int i = 0; i < 5; i++) {
					if (str3[i] != str4[i]) {
						ilosc_kart = 10;
						k = false;
						break;
					} else
						k = true;

				}
				if (k == true) {
					for (int i = 0; i < 5; i++)
						str0[i] = str3[i];
					ilosc_kart = 1;
				}
			}
			if (str[4] != 0 && str[4] != 1)
				ilosc_kart = 10;
		} else
			ilosc_kart = 10;
		str[pozycja] = ilosc_kart;
		ty[pozycja] = ilosc_kart;
	}

	void kareta() {
		int pozycja = 1;
		int ilosc_kart = 0;
		trojka();
		ilosc_kart = str[5];
		if (ilosc_kart == 2) {
			for (int i = 0; i < 5; i++)
				str1[i] = str5[i];
			int l1 = -1;
			int p1 = 0;
			int l2 = -2;
			int p2 = 0;
			int l = 0;
			int arg = 0;
			for (int i = 0; i < 5; i++) {
				if (l == 0) {
					if (str1[i] == 0) {
						l1 = argumenty[i];
						l++;
						p1 = i;
					}
				}
				if (l == 1) {
					if (str1[i] == 0) {
						l2 = argumenty[i];
						l++;
						p2 = i;
					}
				}
				if (str1[i] == 1) {
					arg = argumenty[i];
				}
			}
			if (arg == l1) {
				str1[p1] = 1;
				ilosc_kart = 0;
			}
			if (arg == l2) {
				str1[p2] = 1;
				ilosc_kart = 0;
			}
			if ((arg != l1) && (arg != l2))
				ilosc_kart = 2;
			else {
				para();
				if (str[7] == 3) {
					for (int i = 0; i < 5; i++)
						str1[i] = str7[i];
					ilosc_kart = 3;
				} else {
					najwyzsza_karta();
					for (int i = 0; i < 5; i++) {
						str1[i] = str8[i];
						ilosc_kart = 4;
					}
				}
			}
		}
		if (ilosc_kart == 4) {
			for (int i = 0; i < 5; i++) {
				str1[i] = str8[i];
			}
			ilosc_kart = 4;
		}
		if (ilosc_kart == 3) {
			for (int i = 0; i < 5; i++)
				str1[i] = str7[i];
			ilosc_kart = 3;
		}
		if (ilosc_kart == 2) {
			for (int i = 0; i < 5; i++)
				str1[i] = str5[i];
			ilosc_kart = 2;
		}
		if (ilosc_kart == 0) {
			for (int i = 0; i < 5; i++)
				str1[i] = str5[i];
			int l1 = -1;
			int p1 = 0;
			int l2 = -2;
			int p2 = 0;
			int l = 0;
			int arg = 0;
			for (int i = 0; i < 5; i++) {
				if (l == 0) {
					if (str1[i] == 0) {
						l1 = argumenty[i];
						l++;
						p1 = i;
					}
				}
				if (l == 1) {
					if (str1[i] == 0) {
						l2 = argumenty[i];
						l++;
						p2 = i;
					}
				}
				if (str1[i] == 1) {
					arg = argumenty[i];
				}
			}
			if (arg == l1) {
				str1[p1] = 1;
				ilosc_kart = 0;
			}
			if (arg == l2) {
				str1[p2] = 1;
				ilosc_kart = 0;
			}
		}
		str[pozycja] = ilosc_kart;
		ty[pozycja] = ilosc_kart;
	}

	void full() {
		int pozycja = 2;
		int ilosc_kart = 0;
		trojka();
		ilosc_kart = str[5];
		if (ilosc_kart == 2) {
			for (int i = 0; i < 5; i++)
				str2[i] = str5[i];
			int l1 = -1;
			int p1 = 0;
			int l2 = -2;
			int p2 = 0;
			int l = 0;
			for (int i = 0; i < 5; i++) {
				if (l == 0) {
					if (str2[i] == 0) {
						l1 = argumenty[i];
						l++;
						p1 = i;
					}
				}
				if (l == 1) {
					if (str2[i] == 0) {
						l2 = argumenty[i];
						l++;
						p2 = i;
					}
				}
			}
			if (l1 == l2) {
				str2[p1] = 1;
				str2[p2] = 1;
				ilosc_kart = 0;
			}
		} else {
			dwie_pary();
			ilosc_kart = str[6];
			if (ilosc_kart == 1) {
				for (int i = 0; i < 5; i++)
					str2[i] = str6[i];
			} else {
				para();
				ilosc_kart = str[7];
				for (int i = 0; i < 5; i++)
					str2[i] = str7[i];
			}
		}
		ty[2] = ilosc_kart;
		str[pozycja] = ilosc_kart;
	}

	void kolor() {
		int pozycja = 3;
		int ilosc_kart = 0;
		int s[] = new int[5];
		int kolory[][] = new int[5][5];
		for (int i = 0; i < 5; i++) {
			int l = 0;
			for (int j = 0; j < 5; j++) {
				int k = i;
				String l1 = karty[0][k];
				String l2 = karty[0][j];
				if (l1 == l2) {
					l++;
					kolory[i][j] = 1;
					kolory[i][i] = 1;
				}
			}
			s[i] = l;
		}
		int max = 0;
		int p = 0;
		for (int i = 0; i < 5; i++) {
			if (max < s[i]) {
				max = s[i];
				p = i;
			}
		}
		ilosc_kart = max;
		int a = max;
		str[pozycja] = (int) 5 - a;
		for (int i = 0; i < 5; i++)
			str3[i] = kolory[p][i];
		ty[3] = 5 - a;
		str[3] = ty[3];
	}

	void strit() {
		int pozycja = 4;
		int ilosc_kart = 0;
		int s[] = new int[5];
		int kar[][] = new int[5][5];
		for (int i = 0; i < 5; i++) {
			int l = 0;
			for (int j = i + 1; j < 5; j++) {
				int k = j - 1;
				int l1 = argumenty[k];
				int l2 = argumenty[j];
				if ((l1 - 1) == l2) {
					l++;
					kar[i][k] = 1;
					kar[i][j] = 1;
				}
				if (l > 0) {
					if ((l1 - 1) == l2) {
						l++;
						kar[i][k] = 1;
						kar[i][j] = 1;
					}
					if ((l1 - 2) < l2)
						break;
				} else
					break;
			}
			s[i] = l;
		}
		int p = 0;
		if (s[0] == 4)
			ilosc_kart = 0;
		else {
			int max = s[0];
			for (int i = 1; i < 5; i++) {
				if (max < s[i]) {
					max = s[i];
					p = i;
				}
			}
			ilosc_kart = 4 - max;
		}
		for (int i = 0; i < 5; i++)
			str4[i] = kar[p][i];
		ilosc_kart = 0;
		for (int i = 0; i < 5; i++) {
			if (str4[i] == 0)
				ilosc_kart++;
		}
		str[pozycja] = ilosc_kart;
	}

	void trojka() {
		int pozycja = 5;
		int ilosc_kart = 0;
		str[pozycja] = ilosc_kart;
		boolean trzy = false;
		int i = 0;
		while (i < 4) {
			boolean dwa = false;
			if (argumenty[i] == argumenty[i + 1]) {
				dwa = true;
				str5[i] = 1;
				i++;
				str5[i] = 1;
				i++;
			} else {
				str[i] = 0;
				i++;
			}
			if (dwa == true) {
				if (argumenty[i] == argumenty[i - 1]) {
					str5[i] = 1;
					trzy = true;
				}
			}
			if (trzy == true)
				break;
			else
				dwa = false;
		}
		if (trzy == true)
			ilosc_kart = 2;
		else {
			for (i = 0; i < 5; i++) {
				if (str5[i] == 0)
					ilosc_kart++;
			}
		}
		str[pozycja] = ilosc_kart;
	}

	void dwie_pary() {
		int pozycja = 6;
		int ilosc_kart = 0;
		int pary = 0;
		int i = 0;
		while (i < 4) {
			if (argumenty[i] == argumenty[i + 1]) {
				pary++;
				str6[i] = 1;
				i++;
				str6[i] = 1;
				i++;
			} else {
				str6[i] = 0;
				i++;
			}
		}
		if (pary == 0)
			ilosc_kart = 4;
		if (pary < 2 && pary > 0)
			ilosc_kart = 3;
		if (pary == 2)
			ilosc_kart = 1;
		str[pozycja] = ilosc_kart;
	}

	void para() {
		int pozycja = 7;
		int ilosc_kart = 0;
		int pary = 0;
		int i = 0;
		while (i < 4) {
			if (argumenty[i] == argumenty[i + 1]) {
				pary++;
				str7[i] = 1;
				i++;
				str7[i] = 1;
				i++;
			} else {
				str7[i] = 0;
				i++;
			}
			if (pary == 1)
				break;
		}
		if (pary == 0)
			ilosc_kart = 4;
		if (pary > 0)
			ilosc_kart = 3;
		str[pozycja] = ilosc_kart;
	}

	void najwyzsza_karta() {
		int pozycja = 8;
		int ilosc_kart = 0;
		for (int i = 0; i < 5; i++) {
			if (argumenty[i] < 11) {
				str8[i] = 0;
				ilosc_kart++;
			} else
				str8[i] = 1;
		}
		str[pozycja] = ilosc_kart;
	}

	// metoda pomocnicza, wypisywanie str'ow
	void s() {
		for (int i = 0; i < 9; i++)
			System.out.print(str[i] + " ");
		System.out.printf("");
	}

	void wyp_str0() {
		System.out.println("str0");
		for (int i = 0; i < 5; i++)
			System.out.print(str0[i] + " ");
		System.out.println("");
	}

	void wyp_str1() {
		System.out.println("str1");
		for (int i = 0; i < 5; i++)
			System.out.print(str1[i] + " ");
		System.out.println("");
	}

	void wyp_str2() {
		System.out.println("str2");
		for (int i = 0; i < 5; i++)
			System.out.print(str2[i] + " ");
		System.out.println("");
	}

	void wyp_str3() {
		System.out.println("str3");
		for (int i = 0; i < 5; i++)
			System.out.print(str3[i] + " ");
		System.out.println("");
	}

	void wyp_str4() {
		System.out.println("str4");
		for (int i = 0; i < 5; i++)
			System.out.print(str4[i] + " ");
		System.out.println("");
	}

	void wyp_str5() {
		System.out.println("str5");
		for (int i = 0; i < 5; i++)
			System.out.print(str5[i] + " ");
		System.out.println("");
	}

	void wyp_str6() {
		System.out.println("str6");
		for (int i = 0; i < 5; i++)
			System.out.print(str6[i] + " ");
		System.out.println("");
	}

	void wyp_str7() {
		System.out.println("str7");
		for (int i = 0; i < 5; i++)
			System.out.print(str7[i] + " ");
		System.out.println("");
	}

	void wyp_str8() {
		System.out.println("str8");
		for (int i = 0; i < 5; i++)
			System.out.print(str8[i] + " ");
		System.out.println("");
	}

	void wymien_karty() {
		int ilosc_kart = 0;
		int pozycja = 0;
		int min = 10;
		int l = 0;
		for (int i = 1; i < 4; i++) {
			if (min > ty[i]) {
				min = ty[i];
				l = 1;
				pozycja = i;
			}
			if (min == ty[i])
				l++;
		}
		for (int i = 4; i < 9; i++) {
			if (min > str[i]) {
				min = str[i];
				l = 1;
				pozycja = i;
			}
			if (min == str[i])
				l++;
		}
		int k[] = new int[5];
		if (pozycja == 1) {
			for (int i = 0; i < 5; i++)
				k[i] = str1[i];
		}
		if (pozycja == 2) {
			for (int i = 0; i < 5; i++)
				k[i] = str2[i];
		}
		if (pozycja == 3) {
			for (int i = 0; i < 5; i++)
				k[i] = str3[i];
		}
		if (pozycja == 4) {
			for (int i = 0; i < 5; i++)
				k[i] = str4[i];
		}
		if (pozycja == 5) {
			for (int i = 0; i < 5; i++)
				k[i] = str5[i];
		}
		if (pozycja == 6) {
			for (int i = 0; i < 5; i++)
				k[i] = str6[i];
		}
		if (pozycja == 7) {
			for (int i = 0; i < 5; i++)
				k[i] = str7[i];
		}
		if (pozycja == 8) {
			for (int i = 0; i < 5; i++)
				k[i] = str8[i];
		}
		for (int i = 0; i < min; i++) {
			String[][] kr = Talia.karty();
			if (k[i] == 0) {
				karty[0][i] = kr[0][0];
				karty[1][i] = kr[1][0];
				k[i] = 0;
			}
		}
		Player.uzupelnianie_argumentow(karty, argumenty);
		ulozenie_kart();
	}

	void reka() {
		this.masz = Talia.co_masz(karty, argumenty);
	}

	void na_stol() {
		this.id = stol.wyloz_na_stol(masz, argumenty, karty);
	}
}